In this work the sound from a flute is visualised. The sound file is available for free freesound.org
# ref: https://musicinformationretrieval.com/index.html
import librosa
%matplotlib inline
import matplotlib.pyplot as plt
import librosa.display
# x are the variable values in the audio array, sr is the sample rate (common sampling rate is 44100 Hz)
x, sr = librosa.load('flute.wav')
print(x.shape)
print(sr)
#Audio array visualization
plt.figure(figsize=(14, 5))
librosa.display.waveplot(x, sr=sr)
#Spectrogram visualization
#short time Fourier Transform. Musical signals are highly non-stationary,
#i.e., their statistics change over time. It would be rather meaningless
#to compute a single Fourier transform over an entire 10-minute song.
# X is obtained by computing the Fourier transform for successive frames in a signal.
X = librosa.stft(x)
Xdb = librosa.amplitude_to_db(abs(X))
plt.figure(figsize=(14, 5))
librosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')
#from the following spectrogram can be detemined spectral features such as pitch, pitch class, harmonics, percussive etc.
import IPython.display as ipd
ipd.Audio('flute.wav')